package com.virgo.demo.market.controller.admin;

import com.virgo.common.entity.IResponse;
import com.virgo.common.entity.ListDataVo;
import com.virgo.demo.core.annotation.Log;
import com.virgo.demo.market.domain.bo.FriendLinkBo;
import com.virgo.demo.market.domain.vo.FriendLinkVo;
import com.virgo.demo.market.service.FriendLinkService;
import com.virgo.demo.support.domain.bo.DictTypeBo;
import com.virgo.demo.support.domain.vo.DictTypeVo;
import com.virgo.demo.support.service.DictTypeService;
import com.virgo.limit.annotation.RepeatSubmit;
import com.virgo.web.utils.IRequestUtils;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.util.ObjectUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/manage168/friendLink")
@RequiredArgsConstructor
public class FriendLinkController {

	private final FriendLinkService friendLinkService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	@Log(module = "友情链接", type = "编辑", permission = "friend_link_save")
	@RepeatSubmit
	public IResponse<Void> saveAction(@Validated FriendLinkBo friendLinkBo) {
		friendLinkService.saveFriendLink(friendLinkBo);
		return IResponse.ok();
	}

	@RequestMapping(value = "/del", method = RequestMethod.POST)
	@Log(module = "友情链接", type = "删除", permission = "friend_link_del")
	@RepeatSubmit
	public IResponse<Void> delAction(HttpServletRequest request) {
		String ids = IRequestUtils.getString(request,"ids","");
		if (ObjectUtils.isEmpty(ids)) {
			return IResponse.fail("参数错误");
		}
		friendLinkService.deleteFriendLink(ids);
		return IResponse.ok();
	}

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@Log(permission = "friend_link_list", saveLog = false)
	public IResponse<ListDataVo<FriendLinkVo>> listAction(HttpServletRequest request) {
		return IResponse.ok(friendLinkService.findList(request));
	}
}